﻿@inherits EditDrawerBase<ResourceDto, Guid>
@if (_editModel != null)
{
<Form Loading="@_isLoading"
      Model="@_editModel"
      LabelCol="new ColLayoutParam { Span = 8 }"
      WrapperCol="new ColLayoutParam { Span = 16 }"
      OnFinish="OnFormFinish"
      Context="model"
      Style="min-height:600px;">
    <FormItem Label="编号">
        <Input @bind-Value="@model.Id" Disabled />
    </FormItem>
    <FormItem Label="父级">
        <Input @bind-Value="@model.ParentId" Type="hidden" />
        <TreeSelect TItem="ResourceDto"
                    Style="width:100%;"
                    DataSource="resources"
                    @bind-Value="@ParentId"
                    Placeholder="@localizer["请选择"]"
                    AllowClear="false"
                    TitleExpression="data => data.Name"
                    KeyExpression="data =>data.Id.ToString()"
                    ChildrenExpression="data => data.Children?.ToList()"
                    IsLeafExpression="data => data.Children==null || !data.Children.Any()"
                    TreeDefaultExpandAll="true"
                    ShowExpand="true"
                    DisabledExpression="data=>data.Id.Equals(_editModel.Id)"
                    DataItemExpression="(resources, id) => TreeTools.QueryNode<ResourceDto>(resources.ToArray(),item=>item.Id.ToString().Equals(id),item=>item.Children)">
        </TreeSelect>
    </FormItem>
    <FormItem Label="名称">
        <Input @bind-Value="@model.Name" />
    </FormItem>
    <FormItem Label="键值">
        <Input @bind-Value="@model.Key" />
    </FormItem>
    <FormItem Label="类型">
        <RadioGroup @bind-Value="@(model.Type)">
            @foreach (var gitem in resourceTypes)
            {
                <Radio Value="@(gitem.Key)">@gitem.Value</Radio>
            }
        </RadioGroup>
    </FormItem>
    @if (model.Type.Equals(ResourceType.Menu))
    {
        <FormItem Label="地址">
            <Input @bind-Value="@model.Path" />
        </FormItem>
        <FormItem Label="图标">
            <Input @bind-Value="@model.Icon" />
        </FormItem>

    }
    <FormItem Label="排序">
        <AntDesign.InputNumber @bind-Value="@model.Order" />
    </FormItem>
    <FormItem Label="是否锁定">
        <Switch @bind-Value="@model.IsLocked"></Switch>
    </FormItem>

    <FormItem Label="备注">
        <TextArea AutoSize="true" MinRows="2" MaxRows="6" @bind-Value="@model.Remark"></TextArea>
    </FormItem>

    @if (this.Options.Type.Equals(DrawerInputType.Edit) || this.Options.Type.Equals(DrawerInputType.Select))
    {
        <FormItem Label="创建时间">
            <span>@model.CreatedTime.ToString(ClientConstant.DateTimeFormat)</span>
        </FormItem>
        <FormItem Label="更新时间">
            <span>@model.UpdatedTime?.ToString(ClientConstant.DateTimeFormat)</span>
        </FormItem>
    }
    <FormItem WrapperColOffset="8" WrapperColSpan="16">
        <Space>
            @if (!DrawerInputType.Select.Equals(this.Options.Type))
            {
                <SpaceItem>
                    <Button Type="@ButtonType.Primary" HtmlType="submit">
                        @localizer["保存"]
                    </Button>
                </SpaceItem>
            }
            <SpaceItem>
                <Button OnClick="_=>OnFormCancel()">
                    @localizer["取消"]
                </Button>
            </SpaceItem>
        </Space>
    </FormItem>

</Form>

}